﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Ninject;
using GalaSoft.MvvmLight;
using WebSiteAdminTool.UI.ViewModels.Security.Users;
using WebSiteAdminTool.UI.Services.ModalDialogs;
using WebSiteAdminTool.UI.Ioc.Mappings;
using Ninject.Syntax;
using Ninject.Modules;
using WebSiteAdminTool.UI.Services.Navigation;
using WebSiteAdminTool.UI.ViewModels;
using WebSiteAdminTool.UI.ViewModels.Security.Roles;
using WebSiteAdminTool.UI.RolesService;
using WebSiteAdminTool.UI.MembershipService;
using WebSiteAdminTool.UI.ViewModels.Base;
using WebSiteAdminTool.Common.Ioc;
using WebSiteAdminTool.Common.Utils;
using WebSiteAdminTool.UI.Utils;

namespace WebSiteAdminTool.UI.Ioc
{
    public class ViewModelLocator : BaseLocator
    {
        #region ctors

        public ViewModelLocator()
            : base(ConfigManager.ApplicationMode)
        { }

        #endregion

        #region initialization

        protected override INinjectModule GetDesignTimeBindings()
        {
            // TODO: implement
            return GetRunTimeBindings();
        }

        protected override INinjectModule GetRunTimeBindings()
        {
            return new RunTimeViewModelMappings();
        }

        protected override INinjectModule GetTestTimeBindings()
        {
            // TODO: implement
            return GetRunTimeBindings();
        }

        #endregion

        #region object accessors

        // Global View Models
        public MainViewModel MainViewModel { get { return base.GetObject<MainViewModel>(); } }
        // ============================================= Security - Users
        public CreateUserViewModel CreateUserViewModel()
        {
            var vm = base.GetObject<CreateUserViewModel>();
            vm.Mode = DialogMode.New;
            vm.User = new UserData();

            return vm;
        }
        public EditUserViewModel EditUserViewModel(UserData user)
        {
            var vm = base.GetObject<EditUserViewModel>();
            vm.Mode = DialogMode.Edit;
            vm.User = user.Clone();

            return vm;
        }
        public UserManagementViewModel UserManagementViewModel { get { return base.GetObject<UserManagementViewModel>(); } }
        public UserManagementActionsViewModel UserManagementActionsViewModel { get { return base.GetObject<UserManagementActionsViewModel>(); } }
        public UserListFilterViewModel UserListFilterViewModel { get { return base.GetObject<UserListFilterViewModel>(); } }
        // ============================================= Security - Roles
        public ManageRoleViewModel ManageRoleViewModel(RoleData role = null)
        {
            var vm = base.GetObject<ManageRoleViewModel>();
            if (null == role)
            {
                vm.Mode = DialogMode.New;
                vm.Role = new RoleData();
            }
            else
            {
                vm.Mode = DialogMode.Edit;
                vm.Role = role.Clone();
            }
            return vm;
        }
        public RoleManagementViewModel RoleManagementViewModel { get { return base.GetObject<RoleManagementViewModel>(); } }
        public RoleManagementActionsViewModel RoleManagementActionsViewModel { get { return base.GetObject<RoleManagementActionsViewModel>(); } }

        //// ------------------------------------ Views ------------------------------------------------------
        //public IModalWindow EditUserModalDialogView { get { return kernel.Get<IModalWindow>("EditUserDialog"); } }

        //// ------------------------------------ View Models ------------------------------------------------------

        #endregion
    }
}
